#ifndef _PANEL_H_LULY_
#define _PANEL_H_LULY_
#include "../NinePatch.h"
#include "Layout.h"
#include "UIObject.h"
//面板
//将子对象的位置为相对位置，相对内容区的位置
class Panel : public UIObject {
 private:
  NinePatch* ninePatch;
  Layout* layout;

 protected:
  virtual void init() override;
  virtual void update() override;
  virtual void draw() override;
  virtual void drawArea(const Rect& area) override;
  virtual void updateContentData() override;

 public:
  Panel(std::string uiObjectId, const int x = 0, const int y = 0,
        const int width = 0, const int height = 0, double scale = 1,
        double angle = 0);

  void setWidth(int w) override {
    UIObject::setWidth(w);
    layout->setWidth(w - ninePatch->getContentToLeft() -
                     ninePatch->getContentToRight());
  }

  void setHeight(int h) override {
    UIObject::setHeight(h);
    layout->setHeight(h - ninePatch->getContentToBottom() -
                      ninePatch->getContentToTop());
  }

  void setArrangement(Layout::Arrangement arrangement) {
    layout->setArrangement(arrangement);
  }

  void setAlignment(Layout::Alignment alignment) {
    layout->setAlignment(alignment);
  }

  void setHeightMode(WHMode hm) override {
    UIObject::setHeightMode(hm);
    layout->setHeightMode(hm);
  }
  void setWidthMode(WHMode wm) override {
    UIObject::setWidthMode(wm);
    layout->setWidthMode(wm);
  }
  void setWHMode(WHMode wm, WHMode hm) override {
    UIObject::setHeightMode(hm);
    layout->setHeightMode(hm);
    UIObject::setWidthMode(wm);
    layout->setWidthMode(wm);
  }

  void setWHMode(WHMode m) override {
    UIObject::setWHMode(m);
    layout->setWHMode(m);
  }

  void addChild(UIObject* uiObject) override { layout->addChild(uiObject); }
  ~Panel();
};

#endif